﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace StuApart
{
    public partial class StudentInCheck : Form
    {
        string connStr = Properties.Settings.Default.StuApartConnectionString;
        SqlConnection conn;
        SqlDataAdapter adapter;
        DataTable table = new DataTable();
       

        public StudentInCheck()
        {
            InitializeComponent();
        }
        // 下载于www.mycodes.net
        private void Form1_Load(object sender, EventArgs e)
        {
            
            conn = new SqlConnection(connStr);
            adapter = new SqlDataAdapter("SELECT * FROM student", conn);
            SqlCommandBuilder builder = new SqlCommandBuilder(adapter);
            adapter.InsertCommand = builder.GetInsertCommand();
            adapter.UpdateCommand = builder.GetUpdateCommand();
            adapter.DeleteCommand = builder.GetDeleteCommand();
            adapter.Fill(table);
            bindingSource1.DataSource = table;
            // TODO: 这行代码将数据加载到表“stuApartDataSet.StudentIn”中。您可以根据需要移动或移除它。
            this.studentInTableAdapter.Fill(this.stuApartDataSet.StudentIn);

        }

        private void fillByToolStripButton_Click(object sender, EventArgs e)
        {
            try
            {
                this.studentInTableAdapter.Fill(this.stuApartDataSet.StudentIn);
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }

        }

        private void DisplayMessage()
        {
          


        }
        private void button1_Click(object sender, EventArgs e)
        {
            
           


          
          
           if (textBox1.Text == "" && textBox2.Text == "")
            {
                MessageBox.Show("姓名和学号不能为空!");
            }
            string conditionStr = "";
            if (textBox1.Text.Trim() != "")
            {
                if (conditionStr == "")
                conditionStr = "Name LIKE'" + textBox1.Text.Trim() + "%'";
                else
                conditionStr += "AND Name LIKE'" + textBox1.Text.Trim() + "%'";
            }
            if (textBox2.Text.Trim() != "")
                conditionStr = "No LIKE'" + textBox2.Text.Trim() + "%'";
                studentInBindingSource.Filter = conditionStr;
            
            

       
            
        
        }

        
        
        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Clear();
            textBox2.Clear();
        }

      }

       
    }

